<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Media extends Model
{
    protected $table = 'media';
    protected $primaryKey = 'id';
    public $timestamps = false;
    public function _user()
    {
        return $this->belongsTo('App\Models\User', 'uid');
    }

    public function _comments()
    {
        return $this->hasMany('App\Models\MediaComment');
    }

    public function _star()
    {
        return $this->hasMany('App\Models\MediaStar');
    }

    public function _userName() {
        return $this->belongsTo("App\Models\MediaComment");
    }

    public static function getRowsArray($where=[], $feild='*',$with=[])
    {
        $datas = self::select($feild)->where($where);
        // 关联查询
        if(is_array($with))
            foreach($with as $value)
                $datas = $datas->with($value);
        $datas = $datas->first();

        if(!empty($datas))
            $datas = $datas->toArray();
        return $datas;
    }
}
